package com.sanrenzu.everybodytv.ui.live;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.sanrenzu.everybodytv.R;
import com.sanrenzu.everybodytv.bean.gy.LiveDataBean;

import java.util.List;

/**
 * Created by Administrator on 2016/9/6 0006.
 */
public class LiveGridViewAdapter extends BaseAdapter {
    private Context mContext;
    private List<LiveDataBean> list;
    private LayoutInflater inflater;
    //申明请求管理，用于glide制作圆图
    private RequestManager glideRequest;
    public LiveGridViewAdapter(Context mContext,List<LiveDataBean> list){
        this.mContext=mContext;
        this.list=list;
        inflater= (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder myViewHolder=null;
        if(convertView==null){
            convertView=inflater.inflate(R.layout.gridview_item_livefragment,parent,false);
            myViewHolder=new MyViewHolder(convertView);
            convertView.setTag(myViewHolder);
        }else {
            myViewHolder= (MyViewHolder) convertView.getTag();
        }
        //glide加载圆图的做法
        glideRequest = Glide.with(mContext);
        glideRequest
                .load(list.get(position).getAvatar())
                .transform(new GlideCircleTransform(mContext))
                .into(myViewHolder.imageView_liveFragment_avatar);
        Glide.with(mContext)
                .load(list.get(position).getThumb())
                .into(myViewHolder.imageView_liveFragment_thumbBaiDu);
        myViewHolder.textView_liveFragment_nick.setText(list.get(position).getNick());
        myViewHolder.textView_liveFragment_title.setText(list.get(position).getTitle());
        return convertView;
    }
    class MyViewHolder{
        private ImageView imageView_liveFragment_avatar;
        private ImageView imageView_liveFragment_thumbBaiDu;
        private TextView textView_liveFragment_count;
        private TextView textView_liveFragment_nick;
        private TextView textView_liveFragment_title;
        public MyViewHolder(View convertView){
            imageView_liveFragment_avatar=
                    (ImageView) convertView.findViewById(R.id.imageView_liveFragment_avatar);
            imageView_liveFragment_thumbBaiDu=
                    (ImageView) convertView.findViewById(R.id.imageView_liveFragment_thumbBaiDu);
            textView_liveFragment_count=
                    (TextView) convertView.findViewById(R.id.textView_liveFragment_count);
            textView_liveFragment_nick=
                    (TextView) convertView.findViewById(R.id.textView_liveFragment_nick);
            textView_liveFragment_title=
                    (TextView) convertView.findViewById(R.id.textView_liveFragment_title);
        }
    }
}
